package com.carey.blog.framework.latke.util;

/**
 * SQL type utilities.
 * 
 */
public final class SQLTypes {

	/**
	 * Returns the specified type.
	 * 
	 * @param type
	 *            the specified type
	 * @return the specified type
	 * @see #toSQLExtra(java.lang.String, java.lang.String, java.lang.String[])
	 */
	public static String toSQLExtra(final String type) {
		return type;
	}

	/**
	 * Combines the specified type, legnth and extra.
	 * <P>
	 * For example, the specified type is {@code VARCHAR}, the specified length
	 * is {@code 255} and the specified extra is {@code NOT NULL}, returns
	 * {@code VARCHAR(255) NOT NULL}.
	 * </p>
	 * 
	 * @param type
	 *            the specified type
	 * @param length
	 *            the specified length
	 * @param extras
	 *            the specified extras
	 * @return a combination of the these specified arguments
	 */
	public static String toSQLExtra(final String type, final String length,
			final String... extras) {
		final StringBuilder sb = new StringBuilder(type);
		sb.append("(");
		sb.append(length);
		sb.append(")");

		for (int i = 0; i < extras.length; i++) {
			final String extra = extras[i];
			sb.append(" ");
			sb.append(extra.trim());
		}

		return sb.toString();
	}

	/**
	 * Private default constructor.
	 */
	private SQLTypes() {
	}
}
